﻿


(function () {
    $(function () {
        var _$table = $('#tb');
        this.init = function (modalManager) {
            _modalManager = modalManager;
            _$stopEquipmentInformationForm = _modalManager.getModal().find("form[name=stopEquipmentInformationsForm]");
            //包含时分秒的日期选择器
          
        }
        var _partService = abp.services.app.part;
      
        var _permissions = {
            create: abp.auth.hasPermission("Pages.ANDON.Create"),
            edit: abp.auth.hasPermission("Pages.ANDON.Edit"),
            'delete': abp.auth.hasPermission("Pages.ANDON..Delete")
             
   
        };


        $("input[name=StartDate]").datetimepicker({
            format: 'yyyy-mm-dd hh:ii',
            autoclose: true,
            todayBtn: true,
        });
        $("input[name=EndDate]").datetimepicker({
            format: 'yyyy-mm-dd hh:ii',
            autoclose: true,
            todayBtn: true,
        });
        // #region CRUD按钮操作

        $("#btn-add").click(function () {
            _createOrEditModal.open();
        });

        $("#btn-edit").click(function () {
            var selectedRaido = _$table.bootstrapTable('getSelections');
            if (selectedRaido.length === 0) {
                abp.notify.warn(app.localize('PleaseSelectForEdit'));
            } else {
                _createOrEditModal.open({ id: selectedRaido[0].Id });
            }
        });

        $("#btn-delete").click(function () {
            var selectedRaido = _$table.bootstrapTable('getSelections');
            if (selectedRaido.length === 0) {
                abp.notify.warn(app.localize('PleaseSelectForDelete'));
            } else {
                deletePart(selectedRaido[0]);
            }
        });
        // #endregion
        //
        //删除当前part实体
        function deletePart(part) {
            abp.message.confirm(
                app.localize('PartDeleteWarningMessage', part.alcCodeId),
                    function (isConfirmed) {
                        if (isConfirmed) {
                            _partService.deletePartAsync({
                                id: part.Id
                            }).done(function () {
                                _$table.bootstrapTable('refresh');
                                abp.notify.success(app.localize('SuccessfullyDeleted'));
                            });
                        }
                    }
                );
        }

        //导出为excel文档
        $('#btn-export').click(function () {
            layer.load(0, {
                shade: [0.3, '#000'] //0.1透明度的白色背景
            });

            _partService
                .getPartToExcel({})
                .done(function (result) {
                    layer.closeAll('loading');
                    app.downloadTempFile(result);
                });
        });
        $("#btn-query").click(function () {
            $.post("/Reports_Offline/GetOffline", {
                Time1: $("#StartDate").val(),
                Time2: $("#EndDate").val()
            },
               function (result) {
                   var a = result.length;
                   $('#line1').empty();
                   $('#line2').empty();
                   $('#line3').empty();
                   $('#line4').empty();
                   html = " <div class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>线体编号</div> ";
                   $("#line1").append(html);
                   html = "  <div class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>零件型号</div>  ";
                   $("#line2").append(html);
                   html = " <div class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>上线数量</div>  ";
                   $("#line3").append(html);
                   html = " <div class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>下线数量</div>";
                   $("#line4").append(html);
                   $.each(result, function (i, item) {
                       if (item.LineId == 1) {
                           html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>" + item.LineId + "</div>";
                           $("#line1").append(html);
                           html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>" + item.ALC + "</div>";
                           $("#line2").append(html);
                           html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>" + item.sum + "</div>";
                           $("#line3").append(html);
                           html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>" + item.offline + "</div>";
                           $("#line4").append(html);
                       }
                      
                   });
                   $.each(result, function (i, item) {
                       if (item.LineId == 4) {
                           html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>一线合计</div>";
                           $("#line1").append(html);
                           html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>" + item.ALC + "</div>";
                           $("#line2").append(html);
                           html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>" + item.sum + "</div>";
                           $("#line3").append(html);
                           html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>" + item.offline + "</div>";
                           $("#line4").append(html);
                       }

                   });
                   $.each(result, function (i, item) {
                       if (item.LineId == 2) {
                           html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>"+item.LineId+"</div>";
                           $("#line1").append(html);
                           html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>" + item.ALC + "</div>";
                           $("#line2").append(html);
                           html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>" + item.sum + "</div>";
                           $("#line3").append(html);
                           html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>" + item.offline + "</div>";
                           $("#line4").append(html);
                       }

                   });
                   $.each(result, function (i, item) {
                       if (item.LineId == 5) {
                           html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>二线合计</div>";
                           $("#line1").append(html);
                           html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>" + item.ALC + "</div>";
                           $("#line2").append(html);
                           html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>" + item.sum + "</div>";
                           $("#line3").append(html);
                           html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>" + item.offline + "</div>";
                           $("#line4").append(html);
                       }

                   });
                   $.each(result, function (i, item) {
                       if (item.LineId == 3) {
                           html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>" + item.LineId + "</div>";
                           $("#line1").append(html);
                           html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>" + item.ALC + "</div>";
                           $("#line2").append(html);
                           html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>" + item.sum + "</div>";
                           $("#line3").append(html);
                           html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>" + item.offline + "</div>";
                           $("#line4").append(html);
                       }

                   });
                   $.each(result, function (i, item) {
                       if (item.LineId == 6) {
                           html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>三线合计</div>";
                           $("#line1").append(html);
                           html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>" + item.ALC + "</div>";
                           $("#line2").append(html);
                           html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>" + item.sum + "</div>";
                           $("#line3").append(html);
                           html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;hegiht:10px  width: 100%'>" + item.offline + "</div>";
                           $("#line4").append(html);
                       }

                   });
                   

               })
        });

        //制作Part事件,用于请求变化后，刷新表格信息
        abp.event.on('app.createOrEditPartModalSaved', function () {
            _$table.bootstrapTable('refresh');
        });

        var oTable = new TableInit();
        oTable.Init();
        _$table.bootstrapTable('hideColumn', 'Id');

        //下拉框二级联动
        $("#cartypeId").change(function () {
            //获取工厂的ID
            var factoryID = $("#cartypeId").val();
            //获取车间
            var lst = $("#styleId");
            $.ajax({
                type: "get",
                url: "/Styles/GetAllStyleByCartypeId",
                data: { id: factoryID },
                dataType: 'JSON', //返回数据的格式
                contentType: 'application/json',
                success: function (data, status) {
                    if (status == "success") {
                        lst.empty();//清空下拉框
                        //lst.append("<option value=''> </option>");
                        $.each(data, function (i, item) {
                            html = "<div  class='text-center' style='border-bottom: 1px solid black;border-left: 1px soslid black;  width: 10%'>" + item.ProduceName + "</div>";
                            $("#line1").append(html);

                        });

                        lst.selectpicker('refresh');
                        lst.selectpicker({
                            title: '请选择'
                        });
                    }
                },
                error: function () {
                    abp.notify.error('Error');
                },
            });
        });
    });
})();
